/**
 * Project Name:kany-project-blog-web
 * File Name:RestJaxRsApplication.java
 * Package Name:me.kany.project.blog.appinit
 * Date:2016年9月21日上午11:00:50
 * Copyright (c) 2016, Jason.Wang All Rights Reserved.
 */
package me.kany.project.blog.appinit;

import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.logging.LoggingFeatureAutoDiscoverable;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.ServerProperties;
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
import org.glassfish.jersey.server.spring.scope.RequestContextFilter;

import me.kany.project.blog.resource.filter.SecurityFilter;
import me.kany.project.blog.resource.mapper.AuthenticationExceptionMapper;
import me.kany.project.blog.resource.mapper.FileNotFoundExceptionMapper;
import me.kany.project.blog.resource.mapper.UberExceptionMapper;

/**
 * ClassName:RestJaxRsApplication<br/>
 * Function: Jersey服务注册类<br/>
 * Date:2016年9月21日上午11:00:50<br/>
 * 
 * @author Jason.Wang
 * @version 1.0
 * @since JDK1.7
 * @see
 */
public class RestJaxRsApplication extends ResourceConfig {

	public RestJaxRsApplication() {
		// 包路径下符合要求的类将被发布成webservice
		packages("me.kany.project.blog.resource");

		// register filters
		register(RequestContextFilter.class);
		// 动态注册
		register(RolesAllowedDynamicFeature.class);
		// 角色控制
		register(SecurityFilter.class);

		// register exception mappers
		register(AuthenticationExceptionMapper.class);
		register(FileNotFoundExceptionMapper.class);
		register(UberExceptionMapper.class);

		// register features
		// 注册logger
		register(LoggingFeature.class);
		register(LoggingFeatureAutoDiscoverable.class);
		// 注册json支持
		// register(FastJsonProvider.class);
		// 由于要使用到@JsonFormat，所以需要注册当前的这JSON类
		register(JacksonFeature.class);
		// 文件上传
		register(MultiPartFeature.class);
		
		//属性配置
		/**
		 * 是否禁用application.wadl
		 */
		property(ServerProperties.WADL_FEATURE_DISABLE, false);
		/**
		 * 是否将错误信息回传
		 */
		property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
	}
}
